package main

import (
	"keep_learning_go_2023/week3/server"
	"keep_learning_go_2023/week3/vo"
	"net/http"
)

// 模仿java 中的controller,通过上下文对请求进行操作
func signUp(context *server.HttpContext) {

	signUp := &vo.SignUp{}
	err := context.ReadJson(signUp)
	if err != nil {
		message := err.Error()
		context.WriteJson(server.INTERNAL_ERROR, message, nil)
		return
	}

	message := "success"
	//经过业务逻辑处理后得到的结果
	result := signUp
	context.WriteJson(server.OK, message, result)

}

// http服务的入口，从最简单的http服务开始写
func main() {

	myServer := server.HttpServletFactory("myserver")

	myServer.AddRouter(http.MethodPost, "/signUpWithContext", signUp)

	myServer.Start(":8080")

}
